feat(tools): Add MCP Apps visualization support for search_events - #744
feat(tools): Add MCP Apps visualization support for search_events#744dcramer wants to merge 1 commit into
Conversation
Add interactive chart visualizations for aggregate query results using the MCP Apps protocol. When search_events returns aggregate data, it now includes structured chart data that MCP Apps-compatible clients can render as bar, pie, line charts, tables, or single numbers. Key changes: - Create new mcp-apps-ui package with Chart.js-based visualization - Extend ToolConfig with optional UI metadata for resource URIs - Register UI resources in server for client fetching - Enhance formatters to return chart data alongside text for aggregates - Add chartType field to search_events agent for visualization hints The implementation maintains backward compatibility - clients without MCP Apps support continue to receive text responses. Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com>
b6847a9 to
6388d9c
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6388d9c. Configure here.
| if (!existsSync(htmlPath)) { | ||
| console.error(`Warning: ${htmlPath} not found. Skipping.`); | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Windows path breaks app bundling
Medium Severity
bundle-apps.ts resolves paths with new URL(import.meta.url).pathname instead of fileURLToPath. On Windows that yields an invalid path (leading slash / encoded characters), so the bundled HTML is not found. The script only warns and continues, so the build can succeed without exporting searchEventsChartHtml, leaving the UI resource empty.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 6388d9c. Configure here.
| ), | ||
| allColumns, | ||
| ); | ||
| } |
There was a problem hiding this comment.
Chart instance not destroyed on switch
Low Severity
renderChart destroys currentChart before creating a new chart, but renderNumberDisplay and renderTable replace #content via innerHTML without destroying an existing Chart.js instance. A later number/table result after a chart leaves a live chart bound to a detached canvas.
Additional Locations (2)
Reviewed by Cursor Bugbot for commit 6388d9c. Configure here.
| line: "line", | ||
| }; | ||
| const chartJsType = chartJsTypeMap[chartType] ?? "bar"; | ||
|
|
There was a problem hiding this comment.
Chart labels show "Unknown" for falsy values like 0 and false
In renderChart, labels with numeric value 0, boolean false, or empty string are incorrectly replaced with "Unknown" instead of being displayed correctly.
Evidence
- Line 123 of
app.tsevaluatesString(d[labelField] || "Unknown"), which treats any falsy label value as missing. - Aggregate group-by fields can legitimately be
0(e.g., a numeric status code),false(a boolean flag), or""(an empty tag); these should appear on the axis/pie slice, not as "Unknown". String(0 || "Unknown")yields"Unknown";String(false || "Unknown")yields"Unknown".- The fix is
String(d[labelField] ?? "Unknown")so onlynull/undefinedfall back to "Unknown". - No tests in the PR cover chart label rendering with falsy field values.
Identified by Warden · code-review · N2L-S6C


Add interactive chart visualizations for aggregate query results using the MCP Apps protocol. When
search_eventsreturns aggregate data, it now includes structured chart data that MCP Apps-compatible clients can render as bar, pie, line charts, tables, or single numbers.What this adds
mcp-apps-uipackage - Contains Chart.js-based visualization app bundled as a single HTML file using Viteui://sentry/search-events-chart.htmlresource that clients can fetchsearch_eventsnow includes_meta.ui.resourceUriin its tool definitionHow it works
_meta.ui.resourceUriin tool definitionsearch_eventsreturns aggregate results, the response includes:mimeType: "application/json;chart"containing structured dataapp.ontoolresultand renders the chartBackward compatibility
Clients without MCP Apps support continue to receive text responses exactly as before. The chart data is an additional content block that non-Apps clients simply ignore.
Chart type inference
The system infers chart type based on data shape:
The AI agent can also explicitly suggest a chart type based on query intent.